package com.lly.songhigh.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lly.songhigh.R;
import com.lly.songhigh.application.BaseApplication;
import com.lly.songhigh.cleanchace.DataCleanManager;
import com.lly.songhigh.constant.StringResouce;

/**
 * Created by 李海龙 on 15/11/6.
 */
public class SettingsActivity extends BaseActivity implements View.OnClickListener {

    private RelativeLayout rl_cleanChace;
    private TextView about_yuelv;
    private Toolbar settingsToolbar;
    private TextView chaceSize;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        BaseApplication.getInstance().addActivity(this);
        settingsToolbar = (Toolbar) findViewById(R.id.settings_toolbar);
        settingsToolbar.setNavigationIcon(R.mipmap.toolbar_back);
        settingsToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        settingsToolbar.setTitle(StringResouce.SETTINGS);
        settingsToolbar.setTitleTextColor(0xFFFFFFFF);
        initView();
    }

    private void initView() {
        chaceSize = (TextView) findViewById(R.id.settings_cleanChace);

        rl_cleanChace = (RelativeLayout) findViewById(R.id.rl_cleanChace);
        rl_cleanChace.setOnClickListener(this);

        about_yuelv = (TextView) findViewById(R.id.about_yuelv);
        about_yuelv.setOnClickListener(this);

        try {
            String s = DataCleanManager.getCacheSize(getCacheDir());
            chaceSize.setText(s);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.about_yuelv:
                Intent intent = new Intent(this, AboutActivity.class);
                startActivity(intent);
                break;
            case R.id.rl_cleanChace:
                Log.i("lhl", "lhl====点击");
                final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("清空缓存？");
                builder.setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        dialog.dismiss();
                        DataCleanManager.deleteFolderFile(getCacheDir().toString(), true);
                        try {
                            String s = DataCleanManager.getCacheSize(getCacheDir());
                            chaceSize.setText(s);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
                builder.create().show();


                break;
        }
    }
}
